package com.j48.entrancegurad.service.impl;

import com.j48.entrancegurad.mapper.HostMapper;
import com.j48.entrancegurad.model.Host;
import com.j48.entrancegurad.service.IHostService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class HostService implements IHostService {
    @Autowired
    private HostMapper hostdao;

    /**
     * 查询所有业主
     * @return
     */
    @Override
    public ArrayList<Host> selectAll() {
        ArrayList<Host> lists=new ArrayList<Host>();
        lists=hostdao.selectAll();
        if (lists.size()>0){
            return lists;
        }
        return null;
    }

    /**
     * 按id查询业主
     * @param host
     * @return
     */
    @Override
    public Host selectById(Host host) {
        Host ht=new Host();
        ht=hostdao.selectById(host);
        if (ht!=null){
            return ht;
        }
        return null;
    }

    /**
     * 添加业主
     * @param host 业主对象
     * @return
     */
    @Override
    public boolean addHost(Host host) {
        if (hostdao.insert(host)>0){
            return true;
        }
        return false;
    }

    /**
     * 更新业主信息
     * @param host 业主对象
     * @return
     */
    @Override
    public boolean updateHost(Host host){
        if (hostdao.update(host)>0){
            return true;
        }
        return false;
    }

    /**
     * 按id查询业主并返回集合
     * @param host 业主对象
     * @return
     */
    @Override
    public ArrayList<Host> selectone(Host host){
        return hostdao.selectById1(host);
    }

    /**
     * 按名字查询业主并返回集合
     * @param host
     * @return
     */
    @Override
    public ArrayList<Host> selectByName(Host host) {
        return hostdao.selectByName(host);
    }

    /**
     * 按住址查询业主
     * @param host 业主对象
     * @return
     */
    @Override
    public Host selectByHouse(Host host) {
        return hostdao.selectByHouse(host);
    }

    /**
     * 按电话查询业主
     * @param host
     * @return
     */
    @Override
    public Host selectByPhone(Host host) {
        return hostdao.selectByPhone(host);
    }
}
